package edu.gatech.cs2340.group7.wheresmystuffapp.presenters;

import android.database.SQLException;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DataManager;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.AdminRemoveAccountView;

/**
 * Presenter for allowing an admin to remove an account
 * @author tbowling3
 *
 */
public class AdminRemoveAccountPresenter {
	private AdminRemoveAccountView myView;
	
	public AdminRemoveAccountPresenter(AdminRemoveAccountView view) {
		myView = view;
	}

	/**
	 * Attempts to delete an account and sets the result text in the view
	 * @param username Username of the account to be deleted
	 */
	public void deleteAccount(String username) {
		if(username.isEmpty()) {
			if(username.equals(DataManager.getCurrentAccountName())) {
				myView.setDeleteResult("Suicide Not Allowed");
			}
			else {
				try {
					DatabaseHelper myHelper = new DatabaseHelper(myView);
					boolean ret = myHelper.deleteAccount(username);
					
					if(ret) {
						myView.setDeleteResult("Account deleted");
					}
					else {
						myView.setDeleteResult("Account not deleted");
					}
				}
				catch (SQLException e) {
					myView.setDeleteResult("Error in SQL Database");
					e.printStackTrace();
				}
				finally {
					
				}
			}
		}
		
	}
}
